package logic

import (
	"context"

	"server_1.0/service/college/college"
	"server_1.0/service/college/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryLogic {
	return &QueryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryLogic) Query() (*college.QReps, error) {

	usersHandle := make([]*college.Reps, 0)
	count := 0
	pnos, _ := l.svcCtx.CollegeModel.GetAll(l.ctx)

	for _, item := range pnos {
		usersHandle = append(
			usersHandle,
			&college.Reps{
				No:   item.Cno,
				Name: item.Cname,
			})
		count += 1
	}
	return &college.QReps{
		Count: int64(count),
		QRs:   usersHandle,
	}, nil
}
